import React, { forwardRef, useImperativeHandle } from 'react';
import { Form, Input, Select, DatePicker, Upload, Button, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import styles from './ApplicationForm.module.less';

const { TextArea } = Input;
const { Option } = Select;

interface ApplicationFormProps {
  onSubmit?: (values: any) => void;
  initialValues?: Record<string, any>;
}

const ApplicationForm = forwardRef((props: ApplicationFormProps, ref) => {
  const [form] = Form.useForm();

  useImperativeHandle(ref, () => ({
    validateFields: () => form.validateFields(),
    resetFields: () => form.resetFields(),
  }));

  return (
    <Form
      form={form}
      layout="vertical"
      className={styles.form}
    >
      <Form.Item
        label="项目名称"
        name="projectName"
        rules={[{ required: true, message: '请输入项目名称' }]}
      >
        <Input placeholder="请输入项目名称" />
      </Form.Item>

      <Form.Item
        label="项目编号"
        name="projectCode"
        rules={[{ required: true, message: '请输入项目编号' }]}
      >
        <Input placeholder="请输入项目编号" />
      </Form.Item>

      <Form.Item
        label="预验收完成情况"
        name="preAcceptanceStatus"
        rules={[{ required: true, message: '请选择预验收完成情况' }]}
      >
        <Select placeholder="请选择预验收完成情况">
          <Option value="completed">已完成</Option>
          <Option value="partial">部分完成</Option>
          <Option value="pending">待完成</Option>
        </Select>
      </Form.Item>

      <Form.Item
        label="整改完成情况"
        name="reformStatus"
        rules={[{ required: true, message: '请选择整改完成情况' }]}
      >
        <Select placeholder="请选择整改完成情况">
          <Option value="completed">全部完成</Option>
          <Option value="partial">部分完成</Option>
          <Option value="none">未开始</Option>
        </Select>
      </Form.Item>

      <Form.Item
        label="期望验收时间"
        name="expectedTime"
        rules={[{ required: true, message: '请选择期望验收时间' }]}
      >
        <DatePicker style={{ width: '100%' }} />
      </Form.Item>

      <Form.Item
        label="申请说明"
        name="description"
        rules={[{ required: true, message: '请输入申请说明' }]}
      >
        <TextArea rows={4} placeholder="请输入申请说明" />
      </Form.Item>

      <Form.Item
        label="验收材料"
        name="materials"
        rules={[{ required: true, message: '请上传验收材料' }]}
      >
        <Upload
          multiple
          listType="text"
          action="/api/upload"  // TODO: 替换为实际的上传接口
          beforeUpload={(file) => {
            const isValidSize = file.size / 1024 / 1024 < 50;
            if (!isValidSize) {
              message.error('文件大小不能超过50MB！');
            }
            return isValidSize;
          }}
        >
          <Button icon={<UploadOutlined />}>上传文件</Button>
        </Upload>
      </Form.Item>
    </Form>
  );
});

ApplicationForm.displayName = 'ApplicationForm';

export default ApplicationForm; 